package com.tzy.zookeeper;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.data.Stat;

/**
 * 二、客户端的 curator连接
 * Curator 是 Netflix 公司开源的一套 zookeeper 客户端框架，
 * 解决了很多 Zookeeper 客户端非常底层的细节开发工作，包括连接重连、反复注册 Watcher 和 NodeExistsException 异常等。
 */
@Slf4j
public class CuratorDemo {

    public static void main(String[] args) throws Exception {
        log.info("开始连接");
        Object o = new Object();
        o.equals("");

        CuratorFramework curatorFramework= CuratorFrameworkFactory.
                builder().connectString("123.60.90.103:2181," +
                "123.60.90.103:2181").
                sessionTimeoutMs(4000).retryPolicy(new
                ExponentialBackoffRetry(1000,3)).
                namespace("").build();
        curatorFramework.start();
        Stat stat=new Stat();
        byte[] bytes = curatorFramework.getData().storingStatIn(stat).forPath("/runoob");
        System.out.println(new String(bytes));
        curatorFramework.close();
    }
}
